package com.leo.controller;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;

/**
 * @ClassName SampleController
 * @Description
 * @Author wangss
 * @date 2020.06.20 23:29
 * @Version 1.0
 */
public class SampleController {

    @FXML
    private Label label;

    @FXML
    private Button button2;

    @FXML
    private Button button4;

    public SampleController() {

    }

    @FXML
    public void initialize() {
        System.out.println("项目启动进行初始化");

        // 设置点击方式2：不推荐
        button2.setOnAction(event -> {
            System.out.println("我在controller中被点击了 " + button2.getText());
        });
    }

    /**
     * 设置点击方式3：推荐
     *
     * @param actionEvent
     */
    public void buttonClick(ActionEvent actionEvent) {
        System.out.println(actionEvent.getSource().toString());
    }

    /**
     * 设置点击方式5：推荐    @FXML 可有可无，只需要方法名称对应即可
     */
    @FXML
    public void button5Click() {
        System.out.println("button5 被点击了");
    }

    public Button getButton4() {
        return button4;
    }
}
